#pragma once

#include <unistd.h>
#include <fcntl.h>
#include <iostream>

struct SetNoWaitOrDie
{
    void operator()(int fd)
    {
        int flag = fcntl(fd, F_GETFL, 0);
        if(flag < 0) {
            std::cerr << "Set No Wait err" << std::endl;
            close(fd);
        }
        flag |= O_NONBLOCK;
        fcntl(fd, F_SETFL, flag);
    }
};